package live.jipiao.dao;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import live.common.PropertiesManager;
import live.common.Verifystring;


public class ServiceNotice {
	public void sentToNotice(Map mp){
		String notice_url=PropertiesManager.getInstance().returnPropValue("FLIHGT_SERVICE_NOTICE");
		Map params = new TreeMap();
		params.put("service", mp.get("service"));
		params.put("orderNo", mp.get("orderNo"));
		params.put("status", mp.get("status"));
		params.put("paytype", "A");
		params.put("sign", "TEST"+new Verifystring().returnAirMd5Hex(params));
		String postData = "";
		if (params != null && params.size() > 0) {
			List keys = new ArrayList(params.keySet());
			Collections.sort(keys);
			for (int i = 0; i < keys.size(); i++) {
				String key = (String) keys.get(i);
				String value =  (String)params.get(key);
				if (i == keys.size() - 1) {
					postData += key + "=" + value;
				} else {
					postData += key + "=" + value + "&";
				}
			}
		}
		HttpURLConnection httpURLConnection;
		StringBuilder sb=null;
		try {
			URL url = new URL(notice_url);// 提交地址
			httpURLConnection = (HttpURLConnection) url
					.openConnection();
			httpURLConnection.setDoOutput(true);// 打开写入属性
			httpURLConnection.setDoInput(true);// 打开读取属性
			httpURLConnection.setRequestMethod("POST");// 设置提交方法
			httpURLConnection.setConnectTimeout(10000);// 连接超时时间
			httpURLConnection.setReadTimeout(30000);
			httpURLConnection.connect();
			OutputStream out = httpURLConnection.getOutputStream();
			out.write(postData.getBytes());// 要post的数据，多个以&符号分割
			out.flush();
			out.close();
			BufferedReader in = new BufferedReader(new InputStreamReader(
					(InputStream) httpURLConnection.getInputStream()));
			in.close();
			httpURLConnection.disconnect();// 断开连接
		}catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
